<%@page import="java.util.ArrayList"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="CloudStorage.*" %>
<%
            int size = 0;
            if (session.getAttribute("cart") != null) {
                size = ((Cart) session.getAttribute("cart")).getSize();
            }

            if ( session.getAttribute("status") == null)
            {
                if ( session.getAttribute("cart") != null )
                {
                   size = ((Cart) session.getAttribute("cart")).getSize();
                }
                else
                {
                    Cart cart = new Cart();
                    session.setAttribute("cart", cart);
                    size = 0;
                }
            }
%>
<%! String ConvertToMonth(int no){
    String Month;
    switch (no){
            case 1: Month="Jan";
                    break;
            case 2: Month="Feb";
                    break;
            case 3: Month="Mar";
                    break;
            case 4: Month="Apr";
                    break;
            case 5: Month="May";
                    break;
            case 6: Month="Jun";
                    break;
            case 7: Month="Jul";
                    break;
            case 8: Month="Aug";
                    break;
            case 9: Month="Sep";
                    break;
            case 10: Month="Oct";
                    break;
            case 11: Month="Nov";
                    break;
            case 12: Month="Dec";
                    break;
            default: Month="Mon";
                     break;
    }
    return Month;
    }
%>

<html>
    <head>
        <title>Cloud Share</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="style.css" />
        <link rel="SHORTCUT ICON" href="images/favicon.ico" />
        <style type="text/css">
            <!--
            a:link {
                color: #F6F1F0;
                text-decoration: none;
            }
            a:visited {
                text-decoration: none;
            }
            a:hover {
                text-decoration: none;
            }
            a:active {
                text-decoration: none;
            }
            body,td,th {
                color: #64584C;
            }
#blocks .inside .searchbar #textsearch {
	margin-bottom: 5px;
}
#blocks .inside .searchbar #search {
	margin-bottom: 0px;
	padding-top:3px;
}

            -->
        </style>
    </head>
    <body>
        <%if ( session.getAttribute("alert") != null) {%>
        <script type="text/javascript" >
            window.alert('You are running out of space!');
        </script>
        <%}%>

        <div id="header">
            <div class="inside">
                <a href="#" class="logo"><img src="images/logo2.gif" alt="" width="131" height="83" /></a>
                <p class="slogan">Share on Clouds!</p>
                <div id="cart">
                    <ul>
                        <li><a href="downloadcart.jsp"><img alt="cart" src="images/cart.png">  Download Cart (<%=size%>)</a> </li>
                    </ul>
                </div>
                <a href="faq.jsp" class="rss"><img src="images/rss.jpg" alt="" width="39" height="41" /></a>
            </div>
            <div id="menu">
               <% if (session.getAttribute("status") == null) {%>
                <ul>
                    <li><a href="index.jsp"><img src="images/but_home.jpg" alt="" width="148" height="40" /></a></li>
                    <li><a href="login.jsp"><img src="images/but_login.jpg" alt="" width="147" height="40" /></a></li>
                    <li><a href="register.jsp"><img src="images/but_reg.jpg" alt="" width="146" height="40" /></a></li>
                    <li><a href="downloads.jsp"><img src="images/but_down.jpg" alt="" width="146" height="40" /></a></li>
                    <li><a href="upload.jsp"><img src="images/but_upload.jpg" alt="" width="146" height="40" /></a></li>
                    <li><a href="buy.jsp"><img src="images/but_buy.jpg" alt="" width="146" height="40" /></a></li>
                    
                </ul>
				<% } else { %>
                <ul>
                    <li><a href="index.jsp"><img src="images/but_home.jpg" alt="" width="148" height="40" /></a></li>
                    <li><a href="account.jsp"><img src="images/but_account.jpg" alt="" width="146" height="40" /></a></li>
                    <li><a href="downloads.jsp"><img src="images/but_down.jpg" alt="" width="146" height="40" /></a></li>
                    <li><a href="upload.jsp"><img src="images/but_upload.jpg" alt="" width="146" height="40" /></a></li>
                    <li><a href="buy.jsp"><img src="images/but_buy.jpg" alt="" width="146" height="40" /></a></li>
                    <li><a href="LogoutServlet"><img src="images/but_logout.jpg" alt="" width="147" height="40" /></a></li>
                </ul>
                <%}%>
                
            </div>
            <div class="headimage">
                <img src="images/picture.jpg" alt=""/>
            </div>
        </div>
        <div id="blocks">
            <div class="inside">
                <div class ="searchbar">
                    <form method="get" action="KeywordSearch"> 
                        <input name="keyword" type="text" id="textsearch">
                        <input type="image" name="search" id="search" src="images/search.png" value="Search">
                    </form>
                </div>
                <% if (session.getAttribute("status") == null) {%>
                <div class="block1">
                    <h3>Members Area</h3>
                    <p> <form method="post" action="LoginServlet">
                        <span>Username:
                            <input name="username" type="text">
                        </span>
                        <span>Password : <input name="password" type="password">
                        </span>
                        <input type="image" src="images/login.png" name="submit" />
                    </form>
                </div>
                <div class="block2">
                    <h3>Register Now!</h3>
                    <span>Not yet a member? <br>
                        Register now for free!!! </span>
                    <a href="register.jsp"><img src="images/register.png" alt="" width="77" height="22" /></a>
                </div>
                <div class="block3">
                    <h3>Run out of space?</h3>
                    <span>Buy more space for your account! </span>
                    <a href="buy.jsp"><img src="images/buy.png" alt="" width="77" height="22" /></a>
                </div>
                <%} else {%>
                <div class="block1-logged">
                    <h3>Manage my Account</h3>
                    <span>View your Account Information, <br>
	        Change your personal settings. </span>
                    <a href="account.jsp"><img src="images/my_account_button.png" alt="" width="90" height="22" /></a>
                </div>
                <div class="block2-logged">
                    <h3>Manage My Uploads</h3>
                    <span>View your files and folders, <br>
	        Create new folders,Upload a file. </span>
                    <a href="myuploads.jsp"><img src="images/my-uploads-icon.png" alt="" width="94" height="20" /></a>
                </div>
                <div class="block3-logged">
                    <h3>Run out of space?</h3>
                    <span>Buy more space for your account <br> in extremely low prices! </span>
                    <a href="buy.jsp"><img src="images/buy.png" alt="" width="77" height="22" /></a>
                </div>
            </div>
        </div>
        <%}%><!--kleinei to logarismeno-->
        <div id="main">
            <div class="inside">
                <div class="post">
                    <h3>Newest Files</h3>
                    <%
                                Database database = new Database();
                                ArrayList<File> files;

                                if (session.getAttribute("status") != null)
                                {
                                    files = database.getNewestFiles();
                                }
                                else
                                {
                                    files  = database.getNewestPublicFiles();
                                }


                                for (int i = 0; i < files.size(); i++) {
                                    int ownerId = files.get(i).getOwnerId();
                                    String username = database.getUsername(ownerId);

                    %>
                    <br />
                    <div class="right-post">
                        <h2><a href="viewfile.jsp?fileid=<%=files.get(i).getID()%>"> <%=files.get(i).getName()%> </a></h2>
                        <p class="post-info">
                            <%= files.get(i).getDescription()%>
                        </p>
                        <p class="right"><a href="viewfile.jsp?fileid=<%=files.get(i).getID()%>"><img src="images/more.gif" alt="" width="70" height="17" /></a></p>
                    </div>
                    <div class="left-post">
                        <p class="dateinfo"><%=ConvertToMonth(Integer.parseInt(files.get(i).getDatePublished().substring(5, 7)))%>
                            <span><%=files.get(i).getDatePublished().substring(8)%></span>
                        </p>
                        <div class="post-meta">
                            <ul>
                                <li class="tag"><a href="#"><%= files.get(i).getCategory()%></a></li>
                                <li class="user"><a href="#">by <%= username%> </a></li>
                                <li class="time"><a href="#"><%= String.valueOf(files.get(i).getDownloads())%> Downloads</a></li>
                                <!-- <li class="permalink"><a href="#">Permalink</a></li> -->
                            </ul>
                        </div>
                    </div>
                    <% }%>
                </div>
                <div class="news_block">
                    <h3>Top Downloads</h3>
                    <ul>
                        <%
                                    if (session.getAttribute("status") != null)
                                    {
                                        files = database.getMostPopularFiles();
                                    }
                                    else
                                    {
                                        files = database.getMostPopularPublicFiles();
                                    }

                                    for (int i = 0; i < files.size(); i++)
                                    {
                        %>
                        <li>
                             <a href="viewfile.jsp?fileid=<%=files.get(i).getID()%>"><h2><%= String.valueOf(i + 1)%> : <%= files.get(i).getName()%></h2></a>
                            <p> <%= files.get(i).getDescription()%>
                                <a href="viewfile.jsp?fileid=<%=files.get(i).getID()%>"><img src="images/arrow.gif" alt="" width="9" height="9" /></a>
                            </p>
                        </li>
                        <%}%>
                    </ul>
                </div>
            </div>
        </div>
        <div id="footer">
            <div class="inside">
                <p>Cloud Share &copy; 2010   |  Webdesign by Panoylhs &amp; Roumdic S.A.</p>
            </div>
        </div>
    </body>
</html>
